*************************
* 2017 emissions from NEI
*************************
clear all
version 11
set more off
set memory 400m
cd ~\20_emission_county_level

insheet using emission_county_level_2017.csv, names comma clear

count if ctyfips ==.
count if stfips ==.
drop if stfips == .
gen str3 c_fips = string(ctyfips,"%03.0f")
gen str3 s_fips = string(stfips,"%02.0f")
gen fips_string = s_fips+c_fips
destring fips_string, generate(fips)
drop ctyfips stfips *_fips fips_string

tab tier_1_description 
drop if tier_1_code==13

collapse (sum) total_emissions, by(fips pollutant_code)
tab pollutant_code
drop if pollutant_code=="CO"
drop if pollutant_code=="PM10-PRI"
replace pollutant_code="PM25" if pollutant_code=="PM25-PRI"
reshape wide total_emissions, i(fips) j(pollutant_code) string
ren total_emissionsNH3 nh3
ren total_emissionsNOX nox
ren total_emissionsPM25 pm25
ren total_emissionsSO2 so2
ren total_emissionsVOC voc

codebook fips
drop if fips==.
codebook fips

compress
saveold emission_county_level_2017, replace

